<template>
  <div class="choose-picker">
    <div class="picker-wrap">
      <div class="picker-List" v-for="(item, index) in pickerList" :key="'picker' + index">
        <div class="info-items" @click.stop="onSelect(item)">
          <img src="../../assets/uncheckd.png" alt="" class="uncheckd-ring" />
          <i class="iconfont icon-duoxuan-xuanzhong1 theme-customize-font" v-if="picker && picker.id === item.id"></i>
          <span class="picker-name">{{ item.picker }},</span>
          <span class="picker-phone">{{ formatPhone(item) }}</span>
          <span class="picker-default" v-if="item.is_default === 1">{{ t('default') }}</span>
          <img
            src="../../assets/edite.png"
            class="icon-edit"
            @click="goEdit(item)"
          />
        </div>
      </div>
      <div class="footer-bar">
        <div class="onknow" @click="goEdit()">{{ t('collectionAddress_new_consignee') }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import locale from "../../../../mixins/locale";

export default {
  name: 'ChoosePicker',
  props: {
    picker: Object,
    pickerList: {
      type: Array,
      default: () => []
    }
  },
  mixins: [locale],
  methods: {
    // 跳转编辑页
    goEdit(item) {
      this.$emit('newPicker', item);
    },
    // 格式化电话号码展示 
    formatPhone(item) {
      if (item.currentArea && (item.currentArea.nation_code === '86' || item.currentArea.nation_code === '')) {
        return item.picker_contact
      }
      return `${item.currentArea.nation_code}-${item.picker_contact}`
    },
    // 选择提货人
    onSelect(picker) {
      this.$emit('pickerSelect', picker);
    }
  },
};
</script>

<style lang="scss" scoped>
@import "../../assets/styles/global.scss";
@import "../../assets/styles/common.scss";
.choose-picker {
  .van-popup--bottom.van-popup--round {
    height: 6.4rem;
  }

  .picker-wrap {
    position: relative;
    padding-bottom: 1.3rem;

    .subhead {
      position: absolute;
      top: 0.36rem;
      left: 1.04rem;

      span {
        margin-right: 0.16rem;
      }
    }

    .picker-List {
      .info-items {
        line-height: 0.96rem;
        padding: 0 0.32rem;
        position: relative;
        display: flex;
        align-items: center;

        .uncheckd-ring {
          position: absolute;
          top: 32%;
          left: 5%;
        }

        .icon-duoxuan-xuanzhong1 {
          position: absolute;
          top: -2%;
          left: 5%;
        }

        .icon-edit {
          position: absolute;
          top: 32%;
          right: 5%;
          font-size: 0.34rem;
          color: #c8c9cc;
          width: 0.32rem;
          height: 0.32rem;
        }
      }

      .picker-phone {
        margin-left: 0.1rem;
      }

      .picker-name {
        display: inline-block;
        margin-left: 8%;
        max-width: 2.4rem;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }

      .picker-default {
        height: 0.32rem;
        line-height: 0.32rem;
        background: #ffebeb;
        border-radius: 0.04rem;
        font-size: 0.2rem;
        color: #ff781f;
        margin-left: 0.32rem;
        padding: 0 0.16rem;
      }

      .icon-edit {
        position: absolute;
        top: 32%;
        right: 5%;
        font-size: 0.34rem;
        color: #c8c9cc;
      }

    }

    .footer-bar {
      max-width: 550px;
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
      background-color: #fff;

      .onknow {
        width: 90%;
        height: 0.8rem;
        line-height: 0.8rem;
        text-align: center;
        color: #fff;
        background: #105cfb;
        border-radius: 0.4rem;
        margin: 0.2rem auto;

      }
    }
  }
}
</style>